<?php
namespace Modules\Coupon\Http\Controllers\Admin;

use Modules\Coupon\Entities\CouponActive;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class CouponActiveController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header('Index')
            ->description('description')
            ->body($this->grid());
    }

    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('Detail')
            ->description('description')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header('Edit')
            ->description('description')
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('新增优惠券')
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new CouponActive);

        $grid->id('Id');
        $grid->title('Title');
        $grid->summary('Summary');
        $grid->limit('Limit');
        $grid->released('Released');
        $grid->used('Used');
        $grid->type('Type');
        $grid->param('Param');
        $grid->available_merchants('Available merchants');
        $grid->available_categories('Available categories');
        $grid->available_goods('Available goods');
        $grid->available_members('Available members');
        $grid->start_at('Start at');
        $grid->end_at('End at');
        $grid->status('Status');
        $grid->created_at('Created at');
        $grid->updated_at('Updated at');
        $grid->deleted_at('Deleted at');

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(CouponActive::findOrFail($id));

        $show->id('Id');
        $show->title('Title');
        $show->summary('Summary');
        $show->limit('Limit');
        $show->released('Released');
        $show->used('Used');
        $show->type('Type');
        $show->param('Param');
        $show->available_merchants('Available merchants');
        $show->available_categories('Available categories');
        $show->available_goods('Available goods');
        $show->available_members('Available members');
        $show->start_at('Start at');
        $show->end_at('End at');
        $show->status('Status');
        $show->created_at('Created at');
        $show->updated_at('Updated at');
        $show->deleted_at('Deleted at');

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new CouponActive);

        $form->display('id', 'ID');
        $form->text('title', 'Title')->rules('required');
        $form->text('summary', 'Summary');
        $form->number('limit', 'Limit');
        // $form->number('released', 'Released');
        // $form->number('used', 'Used');
        $form->number('type', 'Type');
        $form->text('param', 'Param');
        $form->text('available_merchants', 'Available merchants');
        $form->text('available_categories', 'Available categories');
        $form->text('available_goods', 'Available goods');
        $form->text('available_members', 'Available members');
        // $form->datetime('start_at', 'Start at')->default(date('Y-m-d H:i:s'));
        // $form->datetime('end_at', 'End at')->default(date('Y-m-d H:i:s'));
        $form->checkbox('status', 'Status');

        return $form;
    }
}
